package com.swyc.osschat.Test.StreamTest.Controller.Stream;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import com.swyc.osschat.Test.LambdaTest.Bean.Student;

/**
 * list转map
 * @author zhaol@yunrong.cn
 * @version V2.1
 * @since 2.1.0 2019/8/9 17:55
 */
public class ToMapTest {
    public static void main(String[] args) {
        List<Student> students = Student.generateData();
        //todo 几种方式根据集合专成map
        LinkedHashMap<String, Student> collect1 = students.stream().collect(Collectors.toMap(Student::getFirstLove, Function.identity(), (key1, key2) -> key2, LinkedHashMap::new));
        HashMap<String, Student> collect2 = students.stream().collect(Collectors.toMap(Student::getFirstLove, Function.identity(), (key1, key2) -> key2, HashMap::new));
        Map<String, Student> collect3 = students.stream().collect(Collectors.toMap(Student::getFirstLove, Function.identity(), (key1, key2) -> key2));
        Map<String, Student> collect4 = students.stream().collect(Collectors.toMap(r -> Student.getFirstLove(r), r -> r, (v1, v2) -> v2));
        HashMap<String, Student> collect5 = students.stream().collect(Collectors.toMap(r -> Student.getFirstLove(r), r -> r, (key1, key2) -> key2, HashMap::new));
        LinkedHashMap<String, Student> collect6 = students.stream().collect(Collectors.toMap(r -> Student.getFirstLove(r), r -> r, (key1, key2) -> key2, LinkedHashMap::new));
        System.out.println("sdasdasd");
    }
}
